package com.ias.agdis_r.fragment.task;

import android.content.Intent;
import android.os.Bundle;
//import android.support.v4.app.Fragment;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.TextView;

import com.ias.agdis_r.R;
import com.ias.agdis_r.activity.task.TaskInfoActivity;
import com.ias.agdis_r.adapter.FTaskGridViewAdapter;
import com.ias.agdis_r.adapter.FTaskListViewAdapter;
import com.ias.agdis_r.manager.DataManager;
import com.ias.agdis_r.manager.JavaBeanManager;
import com.ias.agdis_r.module.MessageModel;

/**
 * Created by guoxr on 2015/9/21.
 */
public class FTaskHisListFragment extends Fragment {
    private ListView mListView;
    private GridView mGridView;
    private FTaskListViewAdapter mAdapter;
    private FTaskGridViewAdapter mGridAdapter;
    private View view;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.task_flight_tab_02, container, false);
        checkInfo();
        if (JavaBeanManager.getInstance().isGridTaskMode()) {
            mGridView = (GridView) view.findViewById(R.id.gridView);
            mGridView.setVisibility(View.VISIBLE);
            mGridAdapter = new FTaskGridViewAdapter(getActivity(), true, false);
            mGridView.setAdapter(mGridAdapter);
            mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    gotoTaskInfoActivity(mGridAdapter.getTNB(position));
                }
            });
        } else {
            mListView = (ListView) view.findViewById(R.id.ListView);
            mListView.setVisibility(View.VISIBLE);
            mAdapter = new FTaskListViewAdapter(getActivity(), true, false);
            mListView.setAdapter(mAdapter);
            mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                    gotoTaskInfoActivity(mAdapter.getTNB(arg2));
                }
            });
        }
        return view;
    }

    private void gotoTaskInfoActivity(String tnb){
        Intent intent = new Intent(getActivity(), TaskInfoActivity.class);
        intent.putExtra(MessageModel.TNB, tnb);
        intent.putExtra("ishis", true);
        startActivity(intent);
    }

    private void checkInfo() {
        TextView noInfo = (TextView) view.findViewById(R.id.tv_noInfo);
        DataManager dm = DataManager.getInstance();
        if (0 == dm.getTaskHistroyWorkList().size()) {
            noInfo.setVisibility(View.VISIBLE);
        } else {
            noInfo.setVisibility(View.GONE);
        }
    }
}
